#region Imports

using System;
using Backend.Domain;
using Microsoft.SharePoint;

#endregion

namespace Backend.Services.SP2007
{

    /// <summary>
    /// Provides functionality to convert lists.
    /// </summary>
    internal static class ListConverter
    {

        #region Constants

        #endregion

        #region Methods - Static Member

        /// <summary>
        /// Converts the given SharePoint list collection to a collection of lists.
        /// </summary>
        /// <param name="sharepointListCollection">
        /// The SharePoint list collection to be converted.
        /// </param>
        /// <returns>
        /// The result of converting <paramref name="sharepointListCollection"/>.
        /// </returns>
        public static ListCollection Convert(SPListCollection sharepointListCollection)
        {
            ListCollection listCollection = new ListCollection();

            foreach (SPList sharepointList in sharepointListCollection)
            {
                List list = ListConverter.Convert(sharepointList);

                listCollection.Add(list);
            }

            return listCollection;
        }

        /// <summary>
        /// Converts the given SharePoint list to a list.
        /// </summary>
        /// <param name="sharepointList">
        /// The SharePoint list to be converted.
        /// </param>
        /// <returns>
        /// The result of converting <paramref name="sharepointList"/>.
        /// </returns>
        public static List Convert(SPList sharepointList)
        {
            List list = new List();

            // set properties
            list.Id = sharepointList.ID;
            list.Name = sharepointList.Title;
            list.DisplayName = sharepointList.Title;
            list.Url = new Uri(
                sharepointList.ParentWeb.Url + 
                sharepointList.DefaultViewUrl);

            return list;
        }

        #endregion

    }

}
